package cn.yunhe.services;

import cn.yunhe.dao.ILoginDao;
import cn.yunhe.entity.User;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;


public class LoginService {
    SqlSession session = null;
    ILoginDao iLoginDao = null;

    /**
     * 用户登录
     *
     * @param user
     * @return
     */
    public User login(User user) {
        User userLogin = null;
        try {
            session = SqlSessionFactoryUtil.getSqlSession();
            iLoginDao = session.getMapper(ILoginDao.class);
            userLogin = iLoginDao.login(user);
        } finally {
            session.close();
        }
        return userLogin;
    }


    public int reg(User user) {
        int flag = 0;
        try {
            session = SqlSessionFactoryUtil.getSqlSession();
            iLoginDao = session.getMapper(ILoginDao.class);
            flag = iLoginDao.reg(user);
            session.commit();
        } finally {
            session.close();
        }
        return flag;
    }

}
